package Review;


public class Test31 {

	public static void main(String[] args) {
		int[] array = {1,-2,3,10,-4,7,2,-5};
		int[] array1 = {-5,-4,-3,-2,-1};
		int[] array2 = {1,-2,5,-3,4};
		int[] array3 = {1,2,3,4,5,6};
        System.out.println(findGreatestOfSum(array1));
	}
    public static int findGreatestOfSum(int[] array){
    	 if(array==null||array.length==0){
    		 System.out.println("�������ݲ��Ϸ�");
    		 return -1;
    	 }
    	 int sum = 0;
		 int result = Integer.MIN_VALUE;
    	 for(int i=0;i<array.length;i++){
    		 if(sum <= 0){
    			 sum = array[i];
    		 }
    		 else{
    			 sum += array[i];
    		 }
    		 
    		 if(sum>result){
    			 result = sum;
    		 }
    	 }
    	 return result;
     }
}


class FindGreatestOfSum{
	
	public static int findGreatestOfSum(int[] array){
		 if(array != null && array.length <= 0){
			 return Integer.MIN_VALUE;
		 }
		 int maxSum = Integer.MIN_VALUE;
		 int sum = 0;
		 for (int i = 0; i < array.length; i++) {
			if (sum < 0) {
				sum = array[i];
			}else{
				sum += array[i];
			}
			if (sum > maxSum) {
				maxSum = sum;
			}
		}
		return maxSum;
	}
}
